<?php
/**
 * 小说Dao
 */

class Dao_NovelChannelRelationModel extends Dao_BaseModel {

    protected $_table = 'novel_channel_relation';

    const NORMAL_STATUS = 1;
    const REDIS_KEYWORD = 'NOVEL_CHAPTER_KEY_';
    const EXTIME        = '86400';

    public function __construct ()
    {
        parent::__construct ();
    }

    /**
     * 获取小说章节列表.
     * @param $wheres
     * @return array|bool
     */
    public function getNovelIds ( $wheres = [] )
    {
        if( !$wheres['r_cate_id'] ){
            return false;
        }
        
        $where    = array ();
        if( $wheres['r_cate_id'] ){
            $where[]  = array ( 'r_cate_id' , $wheres['r_cate_id'] );
        }
        
        $where[]  = array ( 'r_status' , self::NORMAL_STATUS );
        $order    = [ 'r_create_time' => 'DESC' ];
        
        $limit  = 10;
        $offset = 0;
        if( isset( $wheres['page'] ) && $wheres['page'] > 0 ){
            $offset = ($wheres['page'] - 1) * 10;
            if( $wheres['limit'] ){
                $limit = $wheres['limit'];
            }
            $this->limit( $limit , $offset );
        }
        
        $info = parent::getRows ( array ( 'r_cate_id' , 'r_novel_id' , 'r_create_time' ) , $where , $order );
        return $info ? $info : false;
    }
    
}
